import baseRequest from "@/utils/request";

/**
 * 重写request
 * @param config
 * @returns {Promise | Promise<unknown>}
 */
const request = function (config) {
  config.baseURL = process.env.VUE_APP_BASE_API + '/container'
  return baseRequest(config)
}


/**
 * 创建货柜
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function createContainer(data){
  return request({
    url: '/createContainer',
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 获取列表
 * @param params
 * @returns {Promise|Promise<*>}
 */
export function getContainerList(params = {}){
  return request({
    url: '/getContainerList',
    params,
  })
}

/**
 * 获取详情
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function getContainerInfo(id){
  return request({
    url: `/getContainerInfo/${id}`,
  })
}

/**
 * 移除箱唛
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function removeContainerBox(data){
  return request({
    url: '/removeContainerBox',
    data,
    method: 'delete',
    handleError: true,
  })
}


/**
 * 编辑货件
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function editContainerBox(data){
  return request({
    url: '/editContainerBox',
    data,
    method: 'put',
    handleError: true,
  })
}

/**
 * 箱子转移
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function boxChangeContainer(data){
  return request({
    url: '/boxChangeContainer',
    data,
    method: 'post',
    handleError: true,
  })
}

/**
 * 箱子转移
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function boxHdChangeContainer(data){
  return request({
    url: '/boxHdChangeContainer',
    data,
    method: 'post',
    handleError: true,
  })
}

/**
 * 移除货柜
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function removeContainer(id){
  return request({
    url: `/removeContainer/${id}`,
    method: 'delete',
    handleError: true,
  })
}

/**
 * 箱子确认入柜
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function installBox(data){
  return request({
    url: '/installBox',
    method: 'patch',
    handleError: true,
    data,
  })
}

/**
 * 更改货柜状态
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function changeStatus(data){
  return request({
    url: '/changeStatus',
    method: 'patch',
    handleError: true,
    data,
  })
}

/**
 * 箱唛确认已分拣
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function sortingBoxLabel(data){
  return request({
    url: '/sortingBoxLabel',
    method: 'patch',
    handleError: true,
    data
  })
}

/**
 * 货柜确认已分拣
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function finishedSorting(id){
  return request({
    url: '/finishedSorting/' + id,
    method: 'put',
    handleError: true,
  })
}


/**
 * 货柜确认已分拣
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function scanContainerBox(params){
  return request({
    url: '/scanContainerBox',
    method: 'get',
    params,
    handleError: true,
  })
}

/**
 * 全部已装柜
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function containerBoxAllInstall(id){
  return request({
    url: `/containerBoxAllInstall/${id}`,
    method: 'put',
    handleError: true,
  })
}

/**
 * 全部已分拣
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function containerBoxAllSorted(id){
  return request({
    url: `/containerBoxAllSorted/${id}`,
    method: 'put',
    handleError: true,
  })
}
